﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ToursAgencyDAL;

namespace TourAgency.Admin
{
    public partial class Tours : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.gridViewTourOffers.DataSource = ToursAgencyDataFuncs.GetAllTours();
                this.gridViewTourOffers.DataBind();
            }
        }

        protected string EncodeEval(string property)
        {
            string currentProperty = (string)Eval(property);
            string result = Server.HtmlEncode(currentProperty);
            return result;
        }

        protected string GetDateOnly(string property)
        {
            DateTime date = (DateTime)Eval(property);
            string result = date.ToShortDateString();
            return result;
        }

        protected void ShowDetails(object sender, CommandEventArgs e)
        {
            int tourID = int.Parse(e.CommandArgument.ToString());
            var tour = ToursAgencyDataFuncs.GetTourByIDAsIqueriable(tourID);
            this.listViewDetails.DataSource = tour;
            this.listViewDetails.DataBind();

            var hotelFacs = ToursAgencyDataFuncs.GetAllHotelFacilitiesByTourID(tourID);
            this.listViewHotelFacilities.DataSource = hotelFacs;
            this.listViewHotelFacilities.DataBind();
        }

        protected string GetDestinationByID(string property)
        {
            int id = (int)Eval(property);
            string destinationName = ToursAgencyDataFuncs.GetDestinationNameByID(id);
            string encodedDestination = Server.HtmlEncode(destinationName);
            return encodedDestination;
        }

        protected string GetTransportnByID(string property)
        {
            int id = (int)Eval(property);
            string transportName = ToursAgencyDataFuncs.GetTransportNameByID(id);
            string encodedTransport = Server.HtmlEncode(transportName);
            return encodedTransport;
        }

        protected string GetBoardByID(string property)
        {
            int id = (int)Eval(property);
            string boardName = ToursAgencyDataFuncs.GetBoardNameByID(id);
            string encodedBoard = Server.HtmlEncode(boardName);
            return encodedBoard;
        }
    }
}